package cc.javaee.bbs.task;

import cc.javaee.bbs.annotations.Task;
import cc.javaee.bbs.constants.Constants;
import cc.javaee.bbs.model.activity.KbrActivity;
import cc.javaee.bbs.service.activity.ActivityService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author xdw
 */
@Component
public class ActivityStartJob extends AbstractJobTemplate {

    @Resource
    private ActivityService activityService;

    //每10分钟执行
    @Override
    @Task("活动结束跑批任务")
    @Scheduled(cron = "${activity.start}")
    protected void execute() {
        KbrActivity kbrActivity = new KbrActivity();
        kbrActivity.setStatus(0);

        // 获取所有活动尚未开始的任务
        List<KbrActivity> kbrActivities = activityService.find(kbrActivity);

        if (CollectionUtils.isNotEmpty(kbrActivities)) {
            Map<Integer, List<KbrActivity>> mapKbrActivities = kbrActivities.stream().collect(Collectors.groupingBy(KbrActivity::getSignStatus));
            // 获取尚未报名数据
            List<KbrActivity> notStartEd = mapKbrActivities.get(Constants.SignStatus.NOT_STARTED);
            notStartEd.forEach(e -> {
//                e.getEnStartTime().get
            });

            List<KbrActivity> starting = mapKbrActivities.get(Constants.SignStatus.STARTING);
            List<KbrActivity> end = mapKbrActivities.get(Constants.SignStatus.END);

        }

        System.out.println("活动开始");
    }

}
